/*
 * INSANE - Interactive Structural Analysis Environment
 *
 * Copyright (C) 2003-2005
 * Universidade Federal de Minas Gerais
 * Escola de Engenharia
 * Departamento de Engenharia de Estruturas
 * 
 * Author's email :    insane@dees.ufmg.br
 * Author's website :  http://www.dees.ufmg.br/insane
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package br.ufmg.dees.insane.materialMedia.degeneration;

import java.io.Serializable;
import java.util.HashMap;

import br.ufmg.dees.insane.analysisModel.AnalysisModel;
import br.ufmg.dees.insane.materialMedia.constitutiveModel.ConstitutiveModel;
import br.ufmg.dees.insane.util.INaturalCoords;

/**
 *A class representing MaterialPoint.<p>
 *
 *@author CENOURA!!!
 *@version 1.0
 *@since 04/05/2005
 */
public class Representation implements Serializable{

    private static final long serialVersionUID = 1L;

    /** The ConstitutiveModel of this Representation.*/
    private ConstitutiveModel cm;

    /** The AnalysisModel of this Representation.*/
    private AnalysisModel am;

    /** The INatural Coords of this Representation (used to numerical integration).*/
    private INaturalCoords naturalcoords;

    /** The Weight of this Representation.*/
    private double weight;

    /** The map with constitutive variables of this Representation.*/
    private HashMap<Object, Object> constitutiveVariables;

    /** The map with previous variables of this Representation used in nonlinear analysis.*/
    private HashMap<Object, Object> previousVariables;

    /**Constructs a Representation and sets its constitutiveModel.
     * @param constm The constitutiveModel of this Representation.
     */
    public Representation(ConstitutiveModel constm) {
	this.cm=constm;
    }

    /**Constructs a Representation and sets its constitutiveModel.
     * @param constm The constitutiveModel of this Representation.
     * @param am The AnalysisModel of this Representation.
     */
    public Representation(ConstitutiveModel constm, AnalysisModel am) {
	this.cm=constm;
	this.am=am;
    }

    /**Constructs a Representation without fields.*/
    public Representation() {
    }

    /** Returns the ConstitutiveModel of this Representation.
     * @return The ConstitutiveModelof this Representation.
     */
    public ConstitutiveModel getCm() {
	return cm;
    }

    /** Sets the ConstitutiveModel of this Representation.
     * @param cm The ConstitutiveModel of this Representation.
     */
    public void setCm(ConstitutiveModel cm) {
	this.cm = cm;
    }

    /**
     * @return Returns the am.
     */
    public AnalysisModel getAnalysisModel() {
	return am;
    }

    /**
     * @param am The am to set.
     */
    public void setAnalysisModel(AnalysisModel am) {
	this.am = am;
    }

    /** Returns the natural coords of this Representation.
     * @return Returns the naturalcoords.
     */
    public INaturalCoords getNaturalcoords() {
	return naturalcoords;
    }
    /** Sets the natural coords of this Representation.
     * @param naturalcoords The naturalcoords to set.
     */
    public void setNaturalcoords(INaturalCoords naturalcoords) {
	this.naturalcoords = naturalcoords;
    }

    /** Returns the weight of this Representation.
     * @return Returns the weight.
     */
    public double getWeight() {
	return weight;
    }

    /**Sets the weight of this Representation.
     * @param weight The weight to set.
     */
    public void setWeight(double weight) {
	this.weight = weight;
    }

    /** Returns the previous variables object of this Representation.
     * @param key The key of the previous variables object of this Representation.
     * @return The previous variables object of this Representation.
     */
    public Object getPreviousVariables(String key) {
	return previousVariables.get(key);
    }

    /** Returns true if the Representation has the previous variables object for the key.
     * @param key The key of the previous variables object.
     * @return True if the Representation has the previous variables object for the key.
     */
    public boolean previousVariablesContainsKey(String key) {
	return previousVariables.containsKey(key);
    }

    /** Sets a variables object of this Representation at a key.
     * @param key The key to set the point object.
     * @param obj The object to set.
     */
    public void setPreviousVariables(String key, Object obj) {
	previousVariables.put(key, obj);
    }

    /** Returns the Constitutive variables object of this Representation.
     * @param key The key of the Constitutive variables object of this Representation.
     * @return The Constitutive variables object of this Representation.
     */
    public Object getConstitutiveVariables(String key) {
	return constitutiveVariables.get(key);
    }

    /** Returns true if the Representation has the Constitutive variables object for the key.
     * @param key The key of the Constitutive variables object.
     * @return True if the Representation has the Constitutive variables object for the key.
     */
    public boolean constitutiveContainsKey(String key) {
	return constitutiveVariables.containsKey(key);
    }

    /** Sets a Constitutive variables object of this Representation at a key.
     * @param key The key to set the object.
     * @param obj The object to set.
     */
    public void setConstitutiveVariables(String key, Object obj) {
	constitutiveVariables.put(key, obj);
    }

    /**Inits a Representation's HashMap*/
    public void init() {
	this.constitutiveVariables = new HashMap<Object, Object>(this.cm.getNumberOfVariables());
	this.previousVariables = new HashMap<Object, Object>(this.cm.getNumberOfPreviousVariables());	
    }

    /** Asks to the constitutive model to update the internal variables of this material point.
     */
    public void update(){
	this.cm.update(this.previousVariables, this.constitutiveVariables);
    }

    /**
     * @return Returns the constitutiveVariables.
     */
    public HashMap<Object, Object> getConstitutiveVariables() {
	return constitutiveVariables;
    }

    /**
     * @param constitutiveVariables The constitutiveVariables to set.
     */
    public void setConstitutiveVariables(HashMap<Object, Object> constitutiveVariables) {
	this.constitutiveVariables = constitutiveVariables;
    }

    /**
     * @return Returns the previousVariables.
     */
    public HashMap<Object, Object> getPreviousVariables() {
	return previousVariables;
    }

    /**
     * @param previousVariables The previousVariables to set.
     */
    public void setPreviousVariables(HashMap<Object, Object> previousVariables) {
	this.previousVariables = previousVariables;
    }
}
